/*
 * Created by SharpDevelop.
 * User: mac
 * Date: 06.09.2006
 * Time: 15:43
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;

namespace TagTool.GraphicTypes
{
	public enum PrimitiveType
	{
		POINTS = (int)CsGL.OpenGL.GL.GL_POINTS,
		
		LINE = (int)CsGL.OpenGL.GL.GL_LINE,
		LINES = (int)CsGL.OpenGL.GL.GL_LINES,
		LINELOOP = (int)CsGL.OpenGL.GL.GL_LINE_LOOP,
		
		TRIANGLES = (int)CsGL.OpenGL.GL.GL_TRIANGLES,
		TRIANGLEFAN = (int)CsGL.OpenGL.GL.GL_TRIANGLE_FAN,
		TRIANGLESTRIP = (int)CsGL.OpenGL.GL.GL_TRIANGLE_STRIP,
		
		QUADS = (int)CsGL.OpenGL.GL.GL_QUADS,
		QUADSTRIP = (int)CsGL.OpenGL.GL.GL_QUAD_STRIP,
		
		POLYGON = (int)CsGL.OpenGL.GL.GL_POLYGON
	}
	
	[Serializable()]
	public class Primitive : Shape
	{
		private PrimitiveType type = PrimitiveType.QUADS;
		
		private List<ColoredPoint> vertices = new List<ColoredPoint>();
		
		public Primitive()
		{
		}
		
		public PrimitiveType PrimitiveType
		{
			get { return type; }
			set { type = value; }
		}
		
		public void Clear()
		{
			vertices.Clear();
		}
		
		public void Add(ColoredPoint p)
		{
			vertices.Add(p);
		}
		
		public void SetColor(Color color)
		{
			foreach(ColoredPoint p in vertices)
			{
				p.Color = color;
			}
			Update();
		}
		
		protected override void Compile()
		{
			if (vertices.Count > 0 && (type == PrimitiveType.LINELOOP || type == PrimitiveType.LINES || type == PrimitiveType.LINE))
			{
				glLineWidth((float)vertices[0].Width);
			}
			
			glBegin((uint)type);
			
			foreach(ColoredPoint p in vertices)
			{
				
				glColor4d(p.Color.R, p.Color.G, p.Color.B, p.Color.A);
				glVertex3d(p.X, p.Y, p.Z);	
			}
			
			glEnd();
			
			
		}
	}
}
